package com.example.teaching_server.repository;

import com.example.teaching_server.entity.ActivityParticipantEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 活动参与者数据访问层
 */
@Repository
public interface ActivityParticipantRepository extends JpaRepository<ActivityParticipantEntity, Long> {

    @Query("SELECT ap FROM ActivityParticipantEntity ap WHERE ap.userId = :userId AND ap.activityId = :activityId")
    List<ActivityParticipantEntity> findByUserIdAndActivityId(@Param("userId") Long userId,
                                                              @Param("activityId") Long activityId);

    @Query("SELECT COUNT(ap) FROM ActivityParticipantEntity ap WHERE ap.activityId = :activityId")
    Integer countByActivityId(@Param("activityId") Long activityId);
}
